package com.ruoyi.project.query.paeaDsLink.controller;

import java.util.ArrayList;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.utils.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.query.paeaDsLink.domain.PaeaDsLink;
import com.ruoyi.project.query.paeaDsLink.service.IPaeaDsLinkService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import java.util.Arrays;

import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 卡账关系Controller
 *
 * @author gang.wei
 * @date 2020-04-06
 */
@Controller
@RequestMapping("/query/paeaDsLink")
public class PaeaDsLinkController extends BaseController
{
    private String prefix = "query/paeaDsLink";

    @Autowired
    private IPaeaDsLinkService paeaDsLinkService;

    @RequiresPermissions("query:paeaDsLink:view")
    @GetMapping()
    public String paeaDsLink()
    {
        return prefix + "/paeaDsLink";
    }

    /**
     * 查询卡账关系列表
     */
    @RequiresPermissions("query:paeaDsLink:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PaeaDsLink paeaDsLink)
    {
        return getDataTable(new ArrayList<PaeaDsLink>());
    }
    /**
     * 查询卡账关系列表
     */
    @RequiresPermissions("query:paeaDsLink:query")
    @PostMapping("/query")
    @ResponseBody
    public TableDataInfo query(PaeaDsLink paeaDsLink)
    {
        QueryWrapper queryWrapper = new QueryWrapper<PaeaDsLink>();
        if(StringUtils.isNotEmpty(paeaDsLink.getOpc1CardNo())){queryWrapper.like("opc1_Card_No",paeaDsLink.getOpc1CardNo());}
        if(StringUtils.isNotEmpty(paeaDsLink.getOpc1Account())){queryWrapper.like("opc1_Account",paeaDsLink.getOpc1Account());}
        startPage();
        List<PaeaDsLink> list = paeaDsLinkService.list(queryWrapper);
        return getDataTable(list);
    }
    /**
     * 导出卡账关系列表
     */
    @RequiresPermissions("query:paeaDsLink:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PaeaDsLink paeaDsLink)
    {
        List<PaeaDsLink> list = paeaDsLinkService.list(new QueryWrapper<>(paeaDsLink));
        ExcelUtil<PaeaDsLink> util = new ExcelUtil<PaeaDsLink>(PaeaDsLink.class);
        return util.exportExcel(list, "paeaDsLink");
    }

    /**
     * 新增卡账关系
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存卡账关系
     */
    @RequiresPermissions("query:paeaDsLink:add")
    @Log(title = "卡账关系", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PaeaDsLink paeaDsLink)
    {
        return toAjax(paeaDsLinkService.saveOrUpdate(paeaDsLink));
    }

    /**
     * 修改卡账关系
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        PaeaDsLink paeaDsLink = paeaDsLinkService.getById(id);
        mmap.put("paeaDsLink", paeaDsLink);
        return prefix + "/edit";
    }

    /**
     * 修改保存卡账关系
     */
    @RequiresPermissions("query:paeaDsLink:edit")
    @Log(title = "卡账关系", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PaeaDsLink paeaDsLink)
    {
        return toAjax(paeaDsLinkService.saveOrUpdate(paeaDsLink));
    }

    /**
     * 删除卡账关系
     */
    @RequiresPermissions("query:paeaDsLink:remove")
    @Log(title = "卡账关系", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(paeaDsLinkService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
